package fl.android;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OptionalDataException;
import java.io.StreamCorruptedException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import fl.android.Note.Voice;

/**
 * Project Keeps track of notes and song properties and manages things.
 * 
 */
public class Project {
	HashMap<Integer, HashSet<Note>> _notes = new HashMap<Integer, HashSet<Note>>();
	static int endPosition = 0;
	static int samplesPerPosition = Audio.SAMPLERATE;

	private static Project inst = new Project();
	public static HashMap<Integer, HashSet<Note>> notes = inst._notes;
	
	public static Voice selected = Voice.Sin;

	/**
	 * add(Note note) adds a note to the project
	 * 
	 * @param note
	 *            the note to be added
	 */
	static public void add(Note note) {
		assert (!notes.get(note.getNotePosition()).contains(note));
		if (!notes.containsKey(note.getNotePosition()))
			notes.put(note.getNotePosition(), new HashSet<Note>());
		notes.get(note.getNotePosition()).add(note);
		if (endPosition < note.getNotePosition())
			endPosition = note.getNotePosition();
		assert (notes.get(note.getNotePosition()).contains(note));
	}

	/**
	 * remove(Note note) removes a note from the project
	 * 
	 * @param note
	 *            the note to be removed
	 */
	static public void remove(Note note) {
		assert (!notes.get(note.getNotePosition()).contains(note));
		notes.remove(note);
		assert (notes.get(note.getNotePosition()).contains(note));
	}

	/**
	 * Clear() Removes all of the notes from the project.
	 */
	static public void clear() {
		notes.clear();
		assert (notes.isEmpty());
	}

	/**
	 * getNotes() fetches a copy of the notes construct.
	 * 
	 * @return a copy of the notes construct
	 */
	static public HashMap<Integer, HashSet<Note>> getNotes() {
		return new HashMap<Integer, HashSet<Note>>(notes);
	}
}
